const express = require("express");
const router = express.Router();
const userController = require('./controller/adminUserController');
const indexController = require('./controller/adminIndexController');
const pageController = require('./controller/adminPageController');
// 默认请求就是显示主页
router.get('/', (req, res) => {
  res.render('index', {});
});

// 页面请求
router.get('/admin', (req, res) => {
  // pageController.showIndex(req, res);
  res.send('<script>location.href="/admin/index"</script>');
});
router.get('/admin/index', (req, res) => {
  pageController.showIndex(req, res);
});
router.get('/admin/posts', (req, res) => {
  pageController.showPosts(req, res);
});
router.get('/admin/post-add', (req, res) => {
  pageController.showPostAdd(req, res);
});
router.get('/admin/categories', (req, res) => {
  pageController.showCategory(req, res);
});
router.get('/admin/comments', (req, res) => {
  pageController.showComments(req, res);
});
router.get('/admin/users', (req, res) => {
  pageController.showUsers(req, res);
});
router.get('/admin/nav-menus', (req, res) => {
  pageController.showNavMenus(req, res);
});
router.get('/admin/slides', (req, res) => {
  pageController.showSlides(req, res);
});
router.get('/admin/settings', (req, res) => {
  pageController.showSettings(req, res);
});
router.get('/admin/login', (req, res) => {
  pageController.showLogin(req, res);
});

//接口
router.post('/admin_login', (req, res) => {
  userController.user_login(req, res);
});
router.post('/admin_getHeadAndNickname', (req, res) => {
  userController.user_getHeadAndNickname(req, res);
});
router.post('/admin_getAllUser', (req, res) => {
  userController.getAllUser(req, res);
});
router.post('/admin_adduser', (req, res) => {
  userController.addNewUser(req, res);
});
router.post('/admin_getUserInfoById', (req, res) => {
  userController.getUserInfoById(req, res);
});
router.post('/admin_updateUserInfo', (req, res) => {
  userController.updateUserInfo(req, res);
});
router.post('/admin_delUserById', (req, res) => {
  userController.delUserById(req, res);
});
router.get('/admin_delMultiple', (req, res) => {
  userController.delMultiple(req, res);
});

const categoryController = require('./controller/adminCategoryController');
router.post('/admin_getAllCategories', (req, res) => {
  categoryController.getAllCategories(req, res);
});
router.post('/admin_addNewCategory',(req,res)=>{
  categoryController.addNewCategory(req,res);
});
router.get('/admin_deleteCategoryMutilple',(req,res)=>{
  categoryController.deleteCategoryMutilple(req,res);
})

const postController = require('./controller/adminPostController');
router.post('/getPostByQuery', (req, res) => {
  postController.getPostsByQuery(req, res);
});

module.exports = router;